package com.starlink.controller.admin;

import com.github.pagehelper.PageInfo;
import com.starlink.common.WebResponse;
import com.starlink.common.annotation.WebAccess;
import com.starlink.model.request.FreeTemplateRequest;
import com.starlink.model.request.MallBooksDetailAddRequest;
import com.starlink.model.request.mall.FreeTemplateInfoRequest;
import com.starlink.model.vo.FreeTemplateVO;
import com.starlink.model.vo.book.FreeTemplateInfoVO;
import com.starlink.service.FreeTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.SortDefault;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Auther: zhouyuhang01
 * @Date: 2024/4/17 12:35
 * @Description: AdminFreeTemplateController
 * @Version 1.0.0
 */
@RestController
@RequestMapping("/admin/freeTemplate")
@Api(value = "【管理端】运费模板模块", tags = {"【管理端】运费模板模块"})
public class AdminFreeTemplateController {

    @Autowired
    private FreeTemplateService freeTemplateService;

    @WebAccess(login = true)
    @ApiOperation(value = "根据模板ID查询详情", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/get/{id}")
    public WebResponse<FreeTemplateInfoVO> getByKey(@PathVariable("id") long id) {
        return WebResponse.build(freeTemplateService.selectFreeTempInfoByFreeTemplateId(id));
    }

    @WebAccess(login = true)
    @ApiOperation("模板列表分页查询")
    @PostMapping("/pagingQuery")
    public WebResponse<PageInfo<List<FreeTemplateVO>>> pagingQuery(@SortDefault(sort = {"sort_num"}, direction = Sort.Direction.ASC) Pageable pageable,
                                                                   @RequestBody FreeTemplateRequest request) {
        return WebResponse.build(freeTemplateService.pagingQuery(request,pageable));
    }

    @WebAccess(login = true)
    @ApiOperation("编辑模板")
    @PostMapping("/editing")
    public WebResponse<Boolean> editing(@Valid @RequestBody FreeTemplateInfoRequest request) {
        return WebResponse.build(freeTemplateService.editing(request));
    }

    @WebAccess(login = true)
    @ApiOperation("删除模板")
    @PostMapping("/delete")
    public WebResponse<Boolean> deleteByKey(String ids) {
        return WebResponse.build(freeTemplateService.deleteDOById(ids));
    }
}
